import lxml.etree as le

with open('edu.html', 'r', encoding='utf-8') as f:
    html = f.read()
    # 把html转成XML对象
    html_x = le.HTML(html)
    # 得到div对象
    div_x_s = html_x.xpath('//div[@class="classify_cList"]')
    #print(div_x_s)
    data_s = []
    #遍历
    for div_x in div_x_s:
        #1级分类
        category1 = div_x.xpath('./h3/a/text()')[0]
        #2级分类
        category2_s = div_x.xpath('./div/span/a/text()')
        data_s.append(
            {
                'category1':category1,
                'category2_s':category2_s,
            }
        )
    #print(data_s)
    #遍历打印
    for data in data_s:
        print(data['category1'])
        for category2 in data['category2_s']:
            print('    ', category2)